/*
 * \brief  Instance of the timer session interface
 * \author Norman Feske
 * \date   2006-08-15
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _TIMER_SESSION_COMPONENT_
#define _TIMER_SESSION_COMPONENT_

#include <util/list.h>
#include <timer_session/server.h>
#include <session/capability.h>

namespace Timer {

	class Session_component : public Session_server,
	                          public Genode::List<Session_component>::Element
	{
		private:

			/*
			 * To keep things simple, we handle each timer session
			 * by a dedicated entry point and activation.
			 */

			Genode::Msgbuf<256>             _snd_msg, _rcv_msg;
			Genode::Server_activation<4096> _server_activation;
			Genode::Server_entrypoint       _server_entrypoint;
			Genode::Session_capability      _session;

		public:

			/**
			 * Constructor
			 *
			 * \param md_ds  capability of the dataspace that holds
			 *               the session component object
			 */
			Session_component(Genode::Cap_session *cap_session):
				_server_activation(&_snd_msg, &_rcv_msg),
				_server_entrypoint(cap_session, &_server_activation),
				_session(Genode::Session_capability(_server_entrypoint.manage(this)))
			{ }

			~Session_component() {
				_server_entrypoint.dissolve(this); }

			/**
			 * Return capability to this timer session
			 */
			Genode::Session_capability session() { return _session; }


			/*****************************
			 ** Timer session interface **
			 *****************************/

			void msleep(unsigned ms);
	};
}

#endif
